{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8d1d5403",
   "metadata": {},
   "source": [
    "---\n",
    "* 2022-11-12/week12\n",
    "* 课程：python"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e17daa61",
   "metadata": {},
   "source": [
    "## 元组（tuple）\n",
    "> 1.元组的概念和基本形态  \n",
    "> 2.元组的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "da162b39",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1800001, 1800002, 1800003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "user_info = 1800001, 1800002, 1800003\n",
    "print(user_info,type(user_info))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6fd284cc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1800001, 1800002, 1800003] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "user_info_list = [1800001, 1800002, 1800003]\n",
    "print(user_info_list,type(user_info_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "466c672c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1800001\n",
      "(1800001, 1800002)\n"
     ]
    }
   ],
   "source": [
    "# 取值\n",
    "print(user_info[0])\n",
    "#切片\n",
    "print(user_info[:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f87ee21a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f56d5ecf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=11, tm_mday=2, tm_hour=19, tm_min=14, tm_sec=22, tm_wday=2, tm_yday=306, tm_isdst=0)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc0ccda7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# help(time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ca04fc05",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1667387644.7368147"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time() #时间戳，可以进记录互联网中所以数据信息产生、销毁、创建一系列行为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "409b209f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.count(1800001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "fdad5a42",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.index(1800001)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eefe2502",
   "metadata": {},
   "source": [
    "## 2.集合  \n",
    "\n",
    "> 1.集合的概念和性质  \n",
    ">> 1.集合的唯一性  \n",
    ">> 2.集合无序性  \n",
    "\n",
    "> 2.集合的方法  \n",
    ">> 1.交集：逻辑运算符：  setA & setB  ,setA.intersection(B)\n",
    ">> 2.并集：逻辑运算符:  setA | setB , setA.union(B)==> 应用：快速统计两个集合元素的个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "88c71d68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'pear', 'apple', 'orange', 'banana'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n",
    "print(basket,type(basket))   ##唯一性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c5ab408b",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id = {1800002,1800003,1800004,180033}\n",
    "合唱团_user_id = {1800002,1800003,1800011,1800223}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "147fe1c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800002, 1800003}"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id & 合唱团_user_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "ef5bdf80",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800002, 1800003}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.intersection(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "8eda9a56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id) + len(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2632bc3b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id) | len(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "7b0c9d77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{180033, 1800002, 1800003, 1800004, 1800011, 1800223}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.union(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1f02cff8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考：如果是列表的话，想要找出重复的项? 集合的价值\n",
    "舞蹈社_user_id_list =[1800001,1800003,180011,1800122]\n",
    "合唱团_user_id_list =[1800003,1800008,1800111,18001222]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ca32582",
   "metadata": {},
   "source": [
    "## 3.字典（dict）\n",
    "> 1.字典的概念和性质  \n",
    ">> 1.性质：   \n",
    ">>> 1.无序性  \n",
    ">>> 2.key是唯一的（没有重复） \n",
    ">>> 3.key是不可变的\n",
    "> 2.字典的创建   \n",
    ">> 1.  \n",
    ">> 2.使用dict（）方法创建字典  \n",
    "\n",
    "> 3.字典的方法\n",
    "\n",
    "```\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "07565c62",
   "metadata": {},
   "outputs": [],
   "source": [
    "wechat = {\"shh9h78rhg6\":[\"Zhichao\",\"冰岛\",\"朋友圈\",\"男\",\"159\",\"置顶聊天\"],\n",
    "         \"bhidhhdy6684gs\":[\"Jack\",\"香港\"]\n",
    "         }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "faf321ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Zhichao', '冰岛', '朋友圈', '男', '159', '置顶聊天']"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wechat[\"shh9h78rhg6\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "951ee678",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班 = {\n",
    "    1800001:\"李华\",\n",
    "    1800002:\"小明\",\n",
    "    1800002:\"Jack\",\n",
    "    1800004:\"Marry\"\n",
    "       }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "4422c8a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1800001: '李华', 1800002: 'Jack', 1800004: 'Marry'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新1班,type(网新1班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "43766acf",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新2班 = {\n",
    "    1800001:\"小红\",\n",
    "    1800002:\"小明\",\n",
    "    1800002:\"Jack\",\n",
    "    1800004:\"Marry\"\n",
    "       }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "de22d78d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list[9]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list[9]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb72ab26",
   "metadata": {},
   "outputs": [],
   "source": [
    "#课后：\n",
    "预习字典的方法"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
